//
//  JDNewOrderDetailCell.swift
//  DragonWallet
//
//  Created by volantPig on 2025/5/20.
//

import UIKit
import SwiftyJSON

class JDNewOrderDetailCell: UITableViewCell {
    // 结算页面用这个2个数据源
    var selectedShopCartModel: JDShopCartModel?
    var preOrderModel: JDPreOrderModel?
    // 结算页面 个人信息
    var buyerInfoModel: JDAuthenticationListModel?
    
    var orderType: JDOrderType = .waitingPay
    var shopName: String?
    var goodsDetailModel: JDOrderDetailModel?
    
    // 地址信息
    var addressInfoContainerView: UIView?
    var shopperNameLabel: UILabel?
    var shopperTelLabel: UILabel?
    var shopperAddressLabel: UILabel?
    
    var changeAddressButton: UIButton?
    
    var noAddressLabel: UILabel?
    var noAddressArrowImageV: UIImageView?
    
    // 实名认证信息
    var buyerContainerViewTitle: UILabel?
    var buyerContainerView: UIView?
    
    var unRealNameLabel: UILabel?
    var unAuthenImageV: UIImageView?
    var realNameLabel: UILabel?
    var authenticationImageV: UIImageView?
    var buyerIdCard: UILabel?
    var hintLabel: JDPaddingLabel?
    var changeBuyerInfoButton: UIButton?
    // 商品信息
    var goodsContainerView: UIView?
    var storeNameLabel: UILabel?
    var tagLabel: UILabel?
    var goodsInfoTableView: UITableView?
    /// 商品个数
    var goodsCount: Int = 2
    
    var paymentSelectedIndex: Int = -1
    
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.contentView.backgroundColor = .commonColor()
//        self.setupUIElements()
    }
    
    func setupUIElements() {
        self.createAddressInfoView()
        self.newBuyerInfoView()
        self.createGoodsContainerView()
        self.priceDetailView()
        self.deliveryInfoView()
        self.setupPaymentWayView()
        self.createTipsView()
    }
    
    func createAddressInfoView() {
        
        if self.preOrderModel?.defaultAddressId == nil && self.orderType == .settlement {
            self.addressInfoContainerView = UIView()
            self.contentView.addSubview(self.addressInfoContainerView!)
            self.addressInfoContainerView?.snp.makeConstraints({ make in
                make.left.equalTo(self.contentView).offset(12)
                make.right.equalTo(self.contentView).offset(-12)
    //            make.top.equalTo(self.addressInfoViewTitle!.snp.bottom).offset(14)
                make.top.equalTo(self.contentView).offset(10)
            })
            self.addressInfoContainerView?.backgroundColor = .white
            self.addressInfoContainerView?.layer.cornerRadius = 8
            
            self.noAddressLabel = UILabel()
            self.addressInfoContainerView?.addSubview(self.noAddressLabel!)
            self.noAddressLabel?.snp.makeConstraints { make in
                make.left.equalTo(self.addressInfoContainerView!).offset(12)
                make.height.equalTo(20)
                make.top.equalTo(self.addressInfoContainerView!).offset(16)
                make.bottom.equalTo(self.addressInfoContainerView!).offset(-14)
            }
            self.noAddressLabel?.text = "完善收货信息"
            self.noAddressLabel?.labelConfig(textAlignment: .left, font: UIFont.systemFont(ofSize: 14, weight: .regular), textColor: color("#333333"), numberOfLines: 1)
            
            self.noAddressArrowImageV = UIImageView()
            self.addressInfoContainerView?.addSubview(self.noAddressArrowImageV!)
            self.noAddressArrowImageV?.snp.makeConstraints { make in
                make.centerY.equalTo(self.addressInfoContainerView!)
                make.right.equalTo(self.addressInfoContainerView!).offset(-12)
                make.size.equalTo(CGSizeMake(5, 9))
            }
            self.noAddressArrowImageV?.image = UIImage(named: "arrow_right")?.withRenderingMode(.alwaysOriginal)
            
        } else {
            self.addressInfoContainerView = UIView()
            self.contentView.addSubview(self.addressInfoContainerView!)
            self.addressInfoContainerView?.snp.makeConstraints({ make in
                make.left.equalTo(self.contentView).offset(12)
                make.right.equalTo(self.contentView).offset(-12)
                make.top.equalTo(self.contentView).offset(10)
            })
            self.addressInfoContainerView?.backgroundColor = .white
            self.addressInfoContainerView?.layer.cornerRadius = 8
            
            self.shopperNameLabel = UILabel()
            self.addressInfoContainerView?.addSubview(self.shopperNameLabel!)
            self.shopperNameLabel?.snp.makeConstraints({ make in
                make.left.equalTo(self.addressInfoContainerView!).offset(12)
                make.top.equalTo(self.addressInfoContainerView!).offset(16)
                make.height.equalTo(25)
            })
            self.shopperNameLabel?.text = "罗先生"
            self.shopperNameLabel?.labelConfig(textAlignment: .left, font: UIFont.systemFont(ofSize: 18, weight: .semibold), textColor: color("#333333"))
            
            self.shopperTelLabel = UILabel()
            self.addressInfoContainerView?.addSubview(self.shopperTelLabel!)
            self.shopperTelLabel?.snp.makeConstraints({ make in
                make.left.equalTo(self.addressInfoContainerView!).offset(12)
                make.top.equalTo(self.shopperNameLabel!.snp.bottom).offset(5)
                make.height.equalTo(20)
            })
            self.shopperTelLabel?.labelConfig(textAlignment: .left, font: UIFont.systemFont(ofSize: 14, weight: .regular), textColor: color("#333333"))
            self.shopperTelLabel?.text = "13644930209"
            
            self.shopperAddressLabel = UILabel()
            self.addressInfoContainerView?.addSubview(self.shopperAddressLabel!)
            self.shopperAddressLabel?.snp.makeConstraints({ make in
                make.left.equalTo(self.addressInfoContainerView!).offset(12)
                make.top.equalTo(self.shopperTelLabel!.snp.bottom).offset(5)
                make.height.equalTo(20)
                make.bottom.equalTo(self.addressInfoContainerView!).offset(-18)
            })
            self.shopperAddressLabel?.labelConfig(textAlignment: .left, font: UIFont.systemFont(ofSize: 14, weight: .regular), textColor: color("#333333"))
            self.shopperAddressLabel?.text = "辽宁省大连市甘井子区高云路136号2-1"
        }
        
        self.changeAddressButton = UIButton(type: .custom)
        self.addressInfoContainerView?.addSubview(self.changeAddressButton!)
        self.changeAddressButton?.snp.makeConstraints { make in
            make.edges.equalTo(self.addressInfoContainerView!)
        }
//        self.changeAddressButton?.backgroundColor = UIColor.red.withAlphaComponent(0.5)
        
    }
    
    func newBuyerInfoView() {
        
        self.buyerContainerViewTitle = UILabel()
        self.contentView.addSubview(self.buyerContainerViewTitle!)
        self.buyerContainerViewTitle?.snp.makeConstraints({ make in
            make.left.equalTo(self.contentView).offset(24)
            make.top.equalTo(self.addressInfoContainerView!.snp.bottom).offset(22)
            make.height.equalTo(22)
        })
        self.buyerContainerViewTitle?.labelConfig(textAlignment: .left, font: UIFont.systemFont(ofSize: 16, weight: .semibold), textColor: color("#333333"))
        self.buyerContainerViewTitle?.text = "购买人信息"
        
        let inputImgV = UIImageView()
        self.contentView.addSubview(inputImgV)
        inputImgV.snp.makeConstraints { make in
            make.left.equalTo(self.buyerContainerViewTitle!.snp.right).offset(6)
            make.centerY.equalTo(self.buyerContainerViewTitle!)
            make.size.equalTo(CGSizeMake(14, 14))
        }
        inputImgV.image = UIImage(named: "write_image")?.withRenderingMode(.alwaysOriginal)
        
        self.buyerContainerView = UIView()
        self.contentView.addSubview(self.buyerContainerView!)
        self.buyerContainerView?.snp.makeConstraints({ make in
            make.left.equalTo(self.contentView).offset(12)
            make.right.equalTo(self.contentView).offset(-12)
            make.top.equalTo(self.buyerContainerViewTitle!.snp.bottom).offset(14)
            make.height.greaterThanOrEqualTo(50)
        })
        self.buyerContainerView?.layer.cornerRadius = 8
        self.buyerContainerView?.backgroundColor = .white
                
        if self.buyerInfoModel == nil && self.orderType == .settlement {
            self.unRealNameLabel = UILabel()
            self.buyerContainerView?.addSubview(self.unRealNameLabel!)
            self.unRealNameLabel?.snp.makeConstraints({ make in
                make.left.equalTo(self.buyerContainerView!).offset(12)
//                make.centerY.equalTo(self.buyerContainerView!)
                make.top.equalTo(self.buyerContainerView!).offset(16)
                make.height.equalTo(20)
            })
            self.unRealNameLabel?.labelConfig(textAlignment: .left, font: UIFont.systemFont(ofSize: 14, weight: .regular), textColor: color("#333333"), numberOfLines: 1)
            self.unRealNameLabel?.text = "选择实名认证"
            
            self.unAuthenImageV = UIImageView()
            self.buyerContainerView?.addSubview(self.unAuthenImageV!)
            self.unAuthenImageV?.snp.makeConstraints { make in
                make.centerY.equalTo(self.unRealNameLabel!)
                make.right.equalTo(self.buyerContainerView!).offset(-12)
            }
            self.unAuthenImageV?.image = UIImage(named: "arrow_right")?.withRenderingMode(.alwaysOriginal)
            
        } else {
            self.realNameLabel = UILabel()
            self.buyerContainerView?.addSubview(self.realNameLabel!)
            self.realNameLabel?.snp.makeConstraints({ make in
                make.left.equalTo(self.buyerContainerView!).offset(12)
                make.top.equalTo(self.buyerContainerView!).offset(20)
                make.height.equalTo(22)
            })
            self.realNameLabel?.labelConfig(textAlignment: .left, font: UIFont.systemFont(ofSize: 16, weight: .regular), textColor: color("#333333"), numberOfLines: 1)
            self.realNameLabel?.text = "刘德华"
            
            self.authenticationImageV = UIImageView()
            self.buyerContainerView?.addSubview(self.authenticationImageV!)
            self.authenticationImageV?.snp.makeConstraints({ make in
                make.left.equalTo(self.realNameLabel!.snp.right).offset(6)
                make.centerY.equalTo(self.realNameLabel!)
                make.size.equalTo(CGSizeMake(50, 16))
            })
            self.authenticationImageV?.image = UIImage(named: "authentication_ok")?.withRenderingMode(.alwaysOriginal)
            
            self.buyerIdCard = UILabel()
            self.buyerContainerView?.addSubview(self.buyerIdCard!)
            self.buyerIdCard?.snp.makeConstraints({ make in
                make.left.equalTo(self.buyerContainerView!).offset(12)
                make.top.equalTo(self.realNameLabel!.snp.bottom).offset(4)
                make.height.equalTo(20)
            })
            self.buyerIdCard?.labelConfig(textAlignment: .left, font: UIFont.systemFont(ofSize: 14, weight: .regular), textColor: color("#8D9198"), numberOfLines: 1)
            self.buyerIdCard?.text = "210802111010101112"
            
        }
        
        self.hintLabel = JDPaddingLabel()
        self.buyerContainerView?.addSubview(self.hintLabel!)
        self.hintLabel?.snp.makeConstraints({ make in
            make.left.equalTo(self.buyerContainerView!).offset(12)
            make.right.equalTo(self.buyerContainerView!).offset(-12)
            if self.buyerInfoModel == nil && self.orderType == .settlement {
                make.top.equalTo(self.unRealNameLabel!.snp.bottom).offset(16)
            } else {
                make.top.equalTo(self.buyerIdCard!.snp.bottom).offset(16)
            }
            make.bottom.equalTo(self.buyerContainerView!).offset(-16)
        })
        self.hintLabel?.edgeInsets = .init(top: 10, left: 10, bottom: 10, right: 10)
        self.hintLabel?.labelConfig(textAlignment: .left, font: UIFont.systemFont(ofSize: 12, weight: .regular), textColor: color("#8D9198"),numberOfLines: 0)
        self.hintLabel?.text = "提示:海关会与实名认证的用户进行电话回访确认商品信息，如若实名信息有误，无法继续通关，造成的损失，平台不予承担。"
        self.hintLabel?.backgroundColor = color("#F5F6F8")
        self.hintLabel?.makeCorner(8)
        
        if self.buyerInfoModel != nil && self.orderType == .settlement {
            self.unAuthenImageV = UIImageView()
            self.buyerContainerView?.addSubview(self.unAuthenImageV!)
            self.unAuthenImageV?.snp.makeConstraints { make in
                make.right.equalTo(self.buyerContainerView!).offset(-12)
                make.top.equalTo(self.buyerContainerView!)
                make.bottom.equalTo(self.hintLabel!.snp.top)
                make.width.equalTo(5)
            }
            self.unAuthenImageV?.image = UIImage(named: "arrow_right")?.withRenderingMode(.alwaysOriginal)
            self.unAuthenImageV?.contentMode = .scaleAspectFit
        }
        
        self.changeBuyerInfoButton = UIButton(type: .custom)
        self.buyerContainerView?.addSubview(self.changeBuyerInfoButton!)
        self.changeBuyerInfoButton?.snp.makeConstraints { make in
            make.left.right.top.equalTo(self.buyerContainerView!)
            make.bottom.equalTo(self.hintLabel!.snp.top)
        }
//        self.changeBuyerInfoButton?.backgroundColor = UIColor.red.withAlphaComponent(0.5)
    }
    
    func createGoodsContainerView() {
        
        self.goodsContainerView = UIView()
        self.contentView.addSubview(self.goodsContainerView!)
        self.goodsContainerView?.snp.makeConstraints({ make in
            make.left.equalTo(self.contentView).offset(12)
            make.right.equalTo(self.contentView).offset(-12)
            make.top.equalTo(self.buyerContainerView!.snp.bottom).offset(10)
//            make.bottom.equalTo(self.contentView).offset(-10)
        })
        self.goodsContainerView?.backgroundColor = .white
        self.goodsContainerView?.makeCorner(8)
        
        let line = UIView()
        self.goodsContainerView?.addSubview(line)
        line.snp.makeConstraints { make in
            make.left.equalTo(self.goodsContainerView!).offset(12)
            make.right.equalTo(self.goodsContainerView!).offset(-12)
            make.top.equalTo(self.goodsContainerView!).offset(52)
            make.height.equalTo(1)
        }
        line.backgroundColor = color("#F5F6F8")
        
        self.storeNameLabel = UILabel()
        self.goodsContainerView?.addSubview(self.storeNameLabel!)
        self.storeNameLabel?.snp.makeConstraints({ make in
            make.left.equalTo(self.goodsContainerView!).offset(12)
            make.top.equalTo(self.goodsContainerView!)
            make.bottom.equalTo(line.snp.top)
        })
        self.storeNameLabel?.text = "三生有幸茶艺工艺"
        self.storeNameLabel?.labelConfig(textAlignment: .left, font: UIFont.systemFont(ofSize: 16, weight: .semibold), textColor: color("#333333"))
        
        self.tagLabel = UILabel()
        self.goodsContainerView?.addSubview(self.tagLabel!)
        self.tagLabel?.snp.makeConstraints({ make in
            make.right.equalTo(self.goodsContainerView!)
            make.centerY.equalTo(self.storeNameLabel!)
            make.size.equalTo(CGSizeMake(80, 24))
        })
        self.tagLabel?.text = "跨境直邮"
        self.tagLabel?.labelConfig(textAlignment: .center, font: UIFont.systemFont(ofSize: 12, weight: .regular), textColor: .white, numberOfLines: 0)
        self.tagLabel?.backgroundColor = UIColor.horizontalGradientColor(leftColor: color("#FA6161"), rightColor: color("#FA8061"), colorFrame: CGRect.init(x: 0, y: 0, width: 80, height: 24))
        self.tagLabel?.makeBezierPathCorner(UIRectCorner(rawValue: UIRectCorner.topLeft.rawValue|UIRectCorner.bottomLeft.rawValue), 12)
        
        
        self.goodsInfoTableView = UITableView.init(frame: .zero, style: .plain)
        self.goodsContainerView?.addSubview(self.goodsInfoTableView!)
        self.goodsInfoTableView?.snp.makeConstraints({ make in
            make.left.equalTo(self.goodsContainerView!)
            make.right.equalTo(self.goodsContainerView!)
            make.top.equalTo(line.snp.bottom)
//            make.height.equalTo(104*self.goodsCount)
            make.height.equalTo(148*self.goodsCount)
            make.bottom.equalTo(self.goodsContainerView!)
        })
        self.goodsInfoTableView?.delegate = self
        self.goodsInfoTableView?.dataSource = self
        self.goodsInfoTableView?.register(UITableViewCell.self, forCellReuseIdentifier: "goodsCell")
        self.goodsInfoTableView?.separatorStyle = .none
        
        self.goodsInfoTableView?.reloadData()
    }
    
    var priceDetailTitle: UILabel?
    var priceDetailContainerView: UIView?
    /// 商品总价
    var goodsTotalPriceView: JDCellInfoCellSubView?
    /// 增值税
    var taxOneView: JDCellInfoCellSubView?
    /// 消费税
    var taxTwoView: JDCellInfoCellSubView?
    /// 运费
    var sendPriceVIew: JDCellInfoCellSubView?
    /// 合计
    var finalPriceView: JDCellInfoCellSubView?
    
    func priceDetailView() {
        self.priceDetailTitle = UILabel()
        self.contentView.addSubview(self.priceDetailTitle!)
        self.priceDetailTitle?.snp.makeConstraints({ make in
            make.left.equalTo(self.contentView).offset(24)
            make.top.equalTo(self.goodsContainerView!.snp.bottom).offset(22)
            make.height.equalTo(20)
        })
        self.priceDetailTitle?.labelConfig(textAlignment: .left, font: UIFont.systemFont(ofSize: 14, weight: .semibold), textColor: color("#333333"))
        self.priceDetailTitle?.text = "价格明细"
        
        let inputImgV = UIImageView()
        self.contentView.addSubview(inputImgV)
        inputImgV.snp.makeConstraints { make in
            make.left.equalTo(self.priceDetailTitle!.snp.right).offset(6)
            make.centerY.equalTo(self.priceDetailTitle!)
            make.size.equalTo(CGSizeMake(14, 14))
        }
        inputImgV.image = UIImage(named: "write_image")?.withRenderingMode(.alwaysOriginal)
        
        self.priceDetailContainerView = UIView()
        self.contentView.addSubview(self.priceDetailContainerView!)
        self.priceDetailContainerView?.snp.makeConstraints { make in
            make.left.equalTo(self.contentView).offset(12)
            make.right.equalTo(self.contentView).offset(-12)
            make.top.equalTo(self.priceDetailTitle!.snp.bottom).offset(14)
        }
        self.priceDetailContainerView?.makeCorner(8)
        self.priceDetailContainerView?.backgroundColor = .white
        
        self.goodsTotalPriceView = JDCellInfoCellSubView()
        self.priceDetailContainerView?.addSubview(self.goodsTotalPriceView!)
        self.goodsTotalPriceView?.snp.makeConstraints { make in
            make.top.equalTo(self.priceDetailContainerView!).offset(9)
            make.left.equalTo(self.priceDetailContainerView!)//.offset(12)
            make.right.equalTo(self.priceDetailContainerView!)//.offset(-12)
            make.height.equalTo(32)
        }
        self.goodsTotalPriceView?.titleLabel?.text = "商品总价"
        
        self.taxOneView = JDCellInfoCellSubView()
        self.priceDetailContainerView?.addSubview(self.taxOneView!)
        self.taxOneView?.snp.makeConstraints { make in
            make.top.equalTo(self.goodsTotalPriceView!.snp.bottom)
            make.left.equalTo(self.priceDetailContainerView!)//.offset(12)
            make.right.equalTo(self.priceDetailContainerView!)//.offset(-12)
            make.height.equalTo(32)
        }
        self.taxOneView?.titleLabel?.text = "增值税"
        
        self.taxTwoView = JDCellInfoCellSubView()
        self.priceDetailContainerView?.addSubview(self.taxTwoView!)
        self.taxTwoView?.snp.makeConstraints { make in
            make.top.equalTo(self.taxOneView!.snp.bottom)
            make.left.equalTo(self.priceDetailContainerView!)//.offset(12)
            make.right.equalTo(self.priceDetailContainerView!)//.offset(-12)
            make.height.equalTo(32)
        }
        self.taxTwoView?.titleLabel?.text = "消费税"
         
        self.sendPriceVIew = JDCellInfoCellSubView()
        self.priceDetailContainerView?.addSubview(self.sendPriceVIew!)
        self.sendPriceVIew?.snp.makeConstraints { make in
            make.top.equalTo(self.taxTwoView!.snp.bottom)
            make.left.equalTo(self.priceDetailContainerView!)//.offset(12)
            make.right.equalTo(self.priceDetailContainerView!)//.offset(-12)
            make.height.equalTo(32)
        }
        self.sendPriceVIew?.titleLabel?.text = "运费"
        
        let line = UIView()
        self.priceDetailContainerView?.addSubview(line)
        line.snp.makeConstraints { make in
            make.left.equalTo(self.priceDetailContainerView!).offset(12)
            make.right.equalTo(self.priceDetailContainerView!).offset(-12)
            make.top.equalTo(self.sendPriceVIew!.snp.bottom).offset(5)
            make.height.equalTo(1)
        }
        line.backgroundColor = color("#F5F6F8")
        
        self.finalPriceView = JDCellInfoCellSubView()
        self.priceDetailContainerView?.addSubview(self.finalPriceView!)
        self.finalPriceView?.snp.makeConstraints { make in
            make.left.right.equalTo(self.priceDetailContainerView!)
            make.top.equalTo(line.snp.bottom).offset(5)
            make.bottom.equalTo(self.priceDetailContainerView!).offset(-5)
            make.height.equalTo(32)
        }
        self.finalPriceView?.titleLabel?.text = "合计"
    }
    
    var deliveryContainerView: UIView?
    var deliveryTitleLabel: UILabel?
    var deliveryInfoLabel: UILabel?
    var deliveryCopyButton: UIButton?
    /// 海关
    var customsTitleLabel: UILabel?
    var customsInfoLabel: UILabel?
    /// 海关通关编号  复制按钮
    var customsCopyButton: UIButton?
    /// 下单时间
    var orderTimeLabel: JDCellInfoCellSubView?
    /// 支付时间
    var payTimeLabel: JDCellInfoCellSubView?
    /// 支付方式
    var paymentLabel: JDCellInfoCellSubView?
    /// 发货时间
    var sendLabel: JDCellInfoCellSubView?
    /// 完成时间
    var doneTimeLabel: JDCellInfoCellSubView?
    
    
    func deliveryInfoView() {
        // 如果是 结算 页面 这个view不显示  所以 只出处理容器view就好了
        if self.orderType == .settlement {
            self.deliveryContainerView = UIView()
            self.contentView.addSubview(self.deliveryContainerView!)
            self.deliveryContainerView?.snp.makeConstraints { make in
                make.left.equalTo(self.contentView).offset(12)
                make.right.equalTo(self.contentView).offset(-12)
                make.top.equalTo(self.priceDetailContainerView!.snp.bottom)
                make.height.equalTo(0)
            }
            return
        }
        
        self.deliveryContainerView = UIView()
        self.contentView.addSubview(self.deliveryContainerView!)
        self.deliveryContainerView?.snp.makeConstraints { make in
            make.left.equalTo(self.contentView).offset(12)
            make.right.equalTo(self.contentView).offset(-12)
            make.top.equalTo(self.priceDetailContainerView!.snp.bottom).offset(10)
//            make.height.equalTo(82)
        }
        self.deliveryContainerView?.makeCorner(8)
        self.deliveryContainerView?.backgroundColor = .white
        
        
        if self.orderType == .waitingPay || self.orderType == .settlement {
            self.deliveryTitleLabel = UILabel()
            self.deliveryContainerView?.addSubview(self.deliveryTitleLabel!)
            self.deliveryTitleLabel?.snp.makeConstraints { make in
                make.left.equalTo(self.deliveryContainerView!).offset(12)
                make.top.equalTo(self.deliveryContainerView!).offset(15)
                make.height.equalTo(20)
            }
            self.deliveryTitleLabel?.labelConfig(textAlignment: .left, font: UIFont.systemFont(ofSize: 14, weight: .regular), textColor: color("#8D9198"), numberOfLines: 1)
            self.deliveryTitleLabel?.text = "订单编号"
            
            self.deliveryCopyButton = UIButton(type: .custom)
            self.deliveryContainerView?.addSubview(self.deliveryCopyButton!)
            self.deliveryCopyButton?.snp.makeConstraints { make in
                make.right.equalTo(self.deliveryContainerView!).offset(-12)
                make.centerY.equalTo(self.deliveryTitleLabel!)
            }
            self.deliveryCopyButton?.buttonConfig(normalTitle: "复制", normalImageNamed: "", normalTitleColor: color("#FA6161"), titleFont: UIFont.systemFont(ofSize: 14, weight: .regular))
            self.deliveryCopyButton?.addTarget(self, action: #selector(deliveryAddPasteboardAction), for: .touchUpInside)
            
            self.deliveryInfoLabel = UILabel()
            self.deliveryContainerView?.addSubview(self.deliveryInfoLabel!)
            self.deliveryInfoLabel?.snp.makeConstraints { make in
                make.right.equalTo(self.deliveryCopyButton!.snp.left)
                make.centerY.equalTo(self.deliveryTitleLabel!)
            }
            self.deliveryInfoLabel?.labelConfig(textAlignment: .left, font: UIFont.systemFont(ofSize: 14, weight: .regular), textColor: color("#333333"), numberOfLines: 1)
            self.deliveryInfoLabel?.text = "xyx2931931293123 | "
            
            self.orderTimeLabel = JDCellInfoCellSubView()
            self.deliveryContainerView?.addSubview(self.orderTimeLabel!)
            self.orderTimeLabel?.snp.makeConstraints { make in
                make.left.right.equalTo(self.deliveryContainerView!)
                make.top.equalTo(self.deliveryTitleLabel!.snp.bottom).offset(6)
                make.height.equalTo(32)
                make.bottom.equalTo(self.deliveryContainerView!).offset(-10)
            }
            self.orderTimeLabel?.titleLabel?.text = "下单时间"
            self.orderTimeLabel?.descriptionLabel?.text = "2024/03/25 14:30:15"
        } else if self.orderType == .alreadyPay || self.orderType == .refusse {
            self.deliveryTitleLabel = UILabel()
            self.deliveryContainerView?.addSubview(self.deliveryTitleLabel!)
            self.deliveryTitleLabel?.snp.makeConstraints { make in
                make.left.equalTo(self.deliveryContainerView!).offset(12)
                make.top.equalTo(self.deliveryContainerView!).offset(15)
                make.height.equalTo(20)
            }
            self.deliveryTitleLabel?.labelConfig(textAlignment: .left, font: UIFont.systemFont(ofSize: 14, weight: .regular), textColor: color("#8D9198"), numberOfLines: 1)
            self.deliveryTitleLabel?.text = "订单编号"
            
            self.deliveryCopyButton = UIButton(type: .custom)
            self.deliveryContainerView?.addSubview(self.deliveryCopyButton!)
            self.deliveryCopyButton?.snp.makeConstraints { make in
                make.right.equalTo(self.deliveryContainerView!).offset(-12)
                make.centerY.equalTo(self.deliveryTitleLabel!)
            }
            self.deliveryCopyButton?.buttonConfig(normalTitle: "复制", normalImageNamed: "", normalTitleColor: color("#FA6161"), titleFont: UIFont.systemFont(ofSize: 14, weight: .regular))
            self.deliveryCopyButton?.addTarget(self, action: #selector(deliveryAddPasteboardAction), for: .touchUpInside)
            
            self.deliveryInfoLabel = UILabel()
            self.deliveryContainerView?.addSubview(self.deliveryInfoLabel!)
            self.deliveryInfoLabel?.snp.makeConstraints { make in
                make.right.equalTo(self.deliveryCopyButton!.snp.left)
                make.centerY.equalTo(self.deliveryTitleLabel!)
            }
            self.deliveryInfoLabel?.labelConfig(textAlignment: .left, font: UIFont.systemFont(ofSize: 14, weight: .regular), textColor: color("#333333"), numberOfLines: 1)
            self.deliveryInfoLabel?.text = "xyx2931931293123 | "
            
            
            self.customsTitleLabel = UILabel()
            self.deliveryContainerView?.addSubview(self.customsTitleLabel!)
            self.customsTitleLabel?.snp.makeConstraints { make in
                make.left.equalTo(self.deliveryContainerView!).offset(12)
                make.top.equalTo(self.deliveryTitleLabel!.snp.bottom).offset(12)
                make.height.equalTo(20)
            }
            self.customsTitleLabel?.labelConfig(textAlignment: .left, font: UIFont.systemFont(ofSize: 14, weight: .regular), textColor: color("#8D9198"), numberOfLines: 1)
            self.customsTitleLabel?.text = "海关通关编号"
            
            self.customsCopyButton = UIButton(type: .custom)
            self.deliveryContainerView?.addSubview(self.customsCopyButton!)
            self.customsCopyButton?.snp.makeConstraints { make in
                make.right.equalTo(self.deliveryContainerView!).offset(-12)
                make.centerY.equalTo(self.customsTitleLabel!)
            }
            self.customsCopyButton?.buttonConfig(normalTitle: "复制", normalImageNamed: "", normalTitleColor: color("#FA6161"), titleFont: UIFont.systemFont(ofSize: 14, weight: .regular))
            self.customsCopyButton?.addTarget(self, action: #selector(customsAddPasteboardAction), for: .touchUpInside)
            
            self.customsInfoLabel = UILabel()
            self.deliveryContainerView?.addSubview(self.customsInfoLabel!)
            self.customsInfoLabel?.snp.makeConstraints { make in
                make.right.equalTo(self.customsCopyButton!.snp.left)
                make.centerY.equalTo(self.customsTitleLabel!)
            }
            self.customsInfoLabel?.labelConfig(textAlignment: .left, font: UIFont.systemFont(ofSize: 14, weight: .regular), textColor: color("#333333"), numberOfLines: 1)
            self.customsInfoLabel?.text = "haiguan2323242343434 | "
            
            self.orderTimeLabel = JDCellInfoCellSubView()
            self.deliveryContainerView?.addSubview(self.orderTimeLabel!)
            self.orderTimeLabel?.snp.makeConstraints { make in
                make.left.right.equalTo(self.deliveryContainerView!)
                make.top.equalTo(self.customsTitleLabel!.snp.bottom).offset(6)
                make.height.equalTo(32)
            }
            self.orderTimeLabel?.titleLabel?.text = "下单时间"
            self.orderTimeLabel?.descriptionLabel?.text = "2024/03/25 14:30:15"
            
            self.payTimeLabel = JDCellInfoCellSubView()
            self.deliveryContainerView?.addSubview(self.payTimeLabel!)
            self.payTimeLabel?.snp.makeConstraints { make in
                make.left.right.equalTo(self.deliveryContainerView!)
                make.top.equalTo(self.orderTimeLabel!.snp.bottom).offset(6)
                make.height.equalTo(32)
            }
            self.payTimeLabel?.titleLabel?.text = "支付时间"
            self.payTimeLabel?.descriptionLabel?.text = "2024/03/25 14:30:15"
            
            self.paymentLabel = JDCellInfoCellSubView()
            self.deliveryContainerView?.addSubview(self.paymentLabel!)
            self.paymentLabel?.snp.makeConstraints { make in
                make.left.right.equalTo(self.deliveryContainerView!)
                make.top.equalTo(self.payTimeLabel!.snp.bottom).offset(6)
                make.height.equalTo(32)
                make.bottom.equalTo(self.deliveryContainerView!).offset(-10)
            }
            self.paymentLabel?.titleLabel?.text = "支付方式"
            self.paymentLabel?.descriptionLabel?.text = "支付宝"
            
        } else if self.orderType == .completed {
            self.deliveryTitleLabel = UILabel()
            self.deliveryContainerView?.addSubview(self.deliveryTitleLabel!)
            self.deliveryTitleLabel?.snp.makeConstraints { make in
                make.left.equalTo(self.deliveryContainerView!).offset(12)
                make.top.equalTo(self.deliveryContainerView!).offset(15)
                make.height.equalTo(20)
            }
            self.deliveryTitleLabel?.labelConfig(textAlignment: .left, font: UIFont.systemFont(ofSize: 14, weight: .regular), textColor: color("#8D9198"), numberOfLines: 1)
            self.deliveryTitleLabel?.text = "订单编号"
            
            self.deliveryCopyButton = UIButton(type: .custom)
            self.deliveryContainerView?.addSubview(self.deliveryCopyButton!)
            self.deliveryCopyButton?.snp.makeConstraints { make in
                make.right.equalTo(self.deliveryContainerView!).offset(-12)
                make.centerY.equalTo(self.deliveryTitleLabel!)
            }
            self.deliveryCopyButton?.buttonConfig(normalTitle: "复制", normalImageNamed: "", normalTitleColor: color("#FA6161"), titleFont: UIFont.systemFont(ofSize: 14, weight: .regular))
            self.deliveryCopyButton?.addTarget(self, action: #selector(deliveryAddPasteboardAction), for: .touchUpInside)
            
            self.deliveryInfoLabel = UILabel()
            self.deliveryContainerView?.addSubview(self.deliveryInfoLabel!)
            self.deliveryInfoLabel?.snp.makeConstraints { make in
                make.right.equalTo(self.deliveryCopyButton!.snp.left)
                make.centerY.equalTo(self.deliveryTitleLabel!)
            }
            self.deliveryInfoLabel?.labelConfig(textAlignment: .left, font: UIFont.systemFont(ofSize: 14, weight: .regular), textColor: color("#333333"), numberOfLines: 1)
            self.deliveryInfoLabel?.text = "xyx2931931293123 | "
            
            
            self.customsTitleLabel = UILabel()
            self.deliveryContainerView?.addSubview(self.customsTitleLabel!)
            self.customsTitleLabel?.snp.makeConstraints { make in
                make.left.equalTo(self.deliveryContainerView!).offset(12)
                make.top.equalTo(self.deliveryTitleLabel!.snp.bottom).offset(12)
                make.height.equalTo(20)
            }
            self.customsTitleLabel?.labelConfig(textAlignment: .left, font: UIFont.systemFont(ofSize: 14, weight: .regular), textColor: color("#8D9198"), numberOfLines: 1)
            self.customsTitleLabel?.text = "海关通关编号"
            
            self.customsCopyButton = UIButton(type: .custom)
            self.deliveryContainerView?.addSubview(self.customsCopyButton!)
            self.customsCopyButton?.snp.makeConstraints { make in
                make.right.equalTo(self.deliveryContainerView!).offset(-12)
                make.centerY.equalTo(self.customsTitleLabel!)
            }
            self.customsCopyButton?.buttonConfig(normalTitle: "复制", normalImageNamed: "", normalTitleColor: color("#FA6161"), titleFont: UIFont.systemFont(ofSize: 14, weight: .regular))
            self.customsCopyButton?.addTarget(self, action: #selector(customsAddPasteboardAction), for: .touchUpInside)
            
            self.customsInfoLabel = UILabel()
            self.deliveryContainerView?.addSubview(self.customsInfoLabel!)
            self.customsInfoLabel?.snp.makeConstraints { make in
                make.right.equalTo(self.customsCopyButton!.snp.left)
                make.centerY.equalTo(self.customsTitleLabel!)
            }
            self.customsInfoLabel?.labelConfig(textAlignment: .left, font: UIFont.systemFont(ofSize: 14, weight: .regular), textColor: color("#333333"), numberOfLines: 1)
            self.customsInfoLabel?.text = "haiguan2323242343434 | "
            
            self.orderTimeLabel = JDCellInfoCellSubView()
            self.deliveryContainerView?.addSubview(self.orderTimeLabel!)
            self.orderTimeLabel?.snp.makeConstraints { make in
                make.left.right.equalTo(self.deliveryContainerView!)
                make.top.equalTo(self.customsTitleLabel!.snp.bottom).offset(6)
                make.height.equalTo(32)
            }
            self.orderTimeLabel?.titleLabel?.text = "下单时间"
            self.orderTimeLabel?.descriptionLabel?.text = "2024/03/25 14:30:15"
            
            self.payTimeLabel = JDCellInfoCellSubView()
            self.deliveryContainerView?.addSubview(self.payTimeLabel!)
            self.payTimeLabel?.snp.makeConstraints { make in
                make.left.right.equalTo(self.deliveryContainerView!)
                make.top.equalTo(self.orderTimeLabel!.snp.bottom).offset(6)
                make.height.equalTo(32)
            }
            self.payTimeLabel?.titleLabel?.text = "支付时间"
            self.payTimeLabel?.descriptionLabel?.text = "2024/03/25 14:30:15"
            
            
            self.doneTimeLabel = JDCellInfoCellSubView()
            self.deliveryContainerView?.addSubview(self.doneTimeLabel!)
            self.doneTimeLabel?.snp.makeConstraints { make in
                make.left.right.equalTo(self.deliveryContainerView!)
                make.top.equalTo(self.payTimeLabel!.snp.bottom).offset(6)
                make.height.equalTo(32)
            }
            self.doneTimeLabel?.titleLabel?.text = "完成时间"
            self.doneTimeLabel?.descriptionLabel?.text = "2025.01.16 13:14:15"
            
            self.paymentLabel = JDCellInfoCellSubView()
            self.deliveryContainerView?.addSubview(self.paymentLabel!)
            self.paymentLabel?.snp.makeConstraints { make in
                make.left.right.equalTo(self.deliveryContainerView!)
                make.top.equalTo(self.doneTimeLabel!.snp.bottom).offset(6)
                make.height.equalTo(32)
                make.bottom.equalTo(self.deliveryContainerView!).offset(-10)
            }
            self.paymentLabel?.titleLabel?.text = "支付方式"
            self.paymentLabel?.descriptionLabel?.text = "支付宝"
        } else if self.orderType == .pickup {
            self.deliveryTitleLabel = UILabel()
            self.deliveryContainerView?.addSubview(self.deliveryTitleLabel!)
            self.deliveryTitleLabel?.snp.makeConstraints { make in
                make.left.equalTo(self.deliveryContainerView!).offset(12)
                make.top.equalTo(self.deliveryContainerView!).offset(15)
                make.height.equalTo(20)
            }
            self.deliveryTitleLabel?.labelConfig(textAlignment: .left, font: UIFont.systemFont(ofSize: 14, weight: .regular), textColor: color("#8D9198"), numberOfLines: 1)
            self.deliveryTitleLabel?.text = "订单编号"
            
            self.deliveryCopyButton = UIButton(type: .custom)
            self.deliveryContainerView?.addSubview(self.deliveryCopyButton!)
            self.deliveryCopyButton?.snp.makeConstraints { make in
                make.right.equalTo(self.deliveryContainerView!).offset(-12)
                make.centerY.equalTo(self.deliveryTitleLabel!)
            }
            self.deliveryCopyButton?.buttonConfig(normalTitle: "复制", normalImageNamed: "", normalTitleColor: color("#FA6161"), titleFont: UIFont.systemFont(ofSize: 14, weight: .regular))
            self.deliveryCopyButton?.addTarget(self, action: #selector(deliveryAddPasteboardAction), for: .touchUpInside)
            
            self.deliveryInfoLabel = UILabel()
            self.deliveryContainerView?.addSubview(self.deliveryInfoLabel!)
            self.deliveryInfoLabel?.snp.makeConstraints { make in
                make.right.equalTo(self.deliveryCopyButton!.snp.left)
                make.centerY.equalTo(self.deliveryTitleLabel!)
            }
            self.deliveryInfoLabel?.labelConfig(textAlignment: .left, font: UIFont.systemFont(ofSize: 14, weight: .regular), textColor: color("#333333"), numberOfLines: 1)
            self.deliveryInfoLabel?.text = "xyx2931931293123 | "
            
            
            self.customsTitleLabel = UILabel()
            self.deliveryContainerView?.addSubview(self.customsTitleLabel!)
            self.customsTitleLabel?.snp.makeConstraints { make in
                make.left.equalTo(self.deliveryContainerView!).offset(12)
                make.top.equalTo(self.deliveryTitleLabel!.snp.bottom).offset(12)
                make.height.equalTo(20)
            }
            self.customsTitleLabel?.labelConfig(textAlignment: .left, font: UIFont.systemFont(ofSize: 14, weight: .regular), textColor: color("#8D9198"), numberOfLines: 1)
            self.customsTitleLabel?.text = "海关通关编号"
            
            self.customsCopyButton = UIButton(type: .custom)
            self.deliveryContainerView?.addSubview(self.customsCopyButton!)
            self.customsCopyButton?.snp.makeConstraints { make in
                make.right.equalTo(self.deliveryContainerView!).offset(-12)
                make.centerY.equalTo(self.customsTitleLabel!)
            }
            self.customsCopyButton?.buttonConfig(normalTitle: "复制", normalImageNamed: "", normalTitleColor: color("#FA6161"), titleFont: UIFont.systemFont(ofSize: 14, weight: .regular))
            self.customsCopyButton?.addTarget(self, action: #selector(customsAddPasteboardAction), for: .touchUpInside)
            
            self.customsInfoLabel = UILabel()
            self.deliveryContainerView?.addSubview(self.customsInfoLabel!)
            self.customsInfoLabel?.snp.makeConstraints { make in
                make.right.equalTo(self.customsCopyButton!.snp.left)
                make.centerY.equalTo(self.customsTitleLabel!)
            }
            self.customsInfoLabel?.labelConfig(textAlignment: .left, font: UIFont.systemFont(ofSize: 14, weight: .regular), textColor: color("#333333"), numberOfLines: 1)
            self.customsInfoLabel?.text = "haiguan2323242343434 | "
            
            self.orderTimeLabel = JDCellInfoCellSubView()
            self.deliveryContainerView?.addSubview(self.orderTimeLabel!)
            self.orderTimeLabel?.snp.makeConstraints { make in
                make.left.right.equalTo(self.deliveryContainerView!)
                make.top.equalTo(self.customsTitleLabel!.snp.bottom).offset(6)
                make.height.equalTo(32)
            }
            self.orderTimeLabel?.titleLabel?.text = "下单时间"
            self.orderTimeLabel?.descriptionLabel?.text = "2024/03/25 14:30:15"
            
            self.payTimeLabel = JDCellInfoCellSubView()
            self.deliveryContainerView?.addSubview(self.payTimeLabel!)
            self.payTimeLabel?.snp.makeConstraints { make in
                make.left.right.equalTo(self.deliveryContainerView!)
                make.top.equalTo(self.orderTimeLabel!.snp.bottom).offset(6)
                make.height.equalTo(32)
            }
            self.payTimeLabel?.titleLabel?.text = "支付时间"
            self.payTimeLabel?.descriptionLabel?.text = "2024/03/25 14:30:15"
            
            
            self.sendLabel = JDCellInfoCellSubView()
            self.deliveryContainerView?.addSubview(self.sendLabel!)
            self.sendLabel?.snp.makeConstraints { make in
                make.left.right.equalTo(self.deliveryContainerView!)
                make.top.equalTo(self.payTimeLabel!.snp.bottom).offset(6)
                make.height.equalTo(32)
            }
            self.sendLabel?.titleLabel?.text = "发货时间"
            self.sendLabel?.descriptionLabel?.text = "2025.01.16 13:14:15"
            
            self.paymentLabel = JDCellInfoCellSubView()
            self.deliveryContainerView?.addSubview(self.paymentLabel!)
            self.paymentLabel?.snp.makeConstraints { make in
                make.left.right.equalTo(self.deliveryContainerView!)
                make.top.equalTo(self.sendLabel!.snp.bottom).offset(6)
                make.height.equalTo(32)
                make.bottom.equalTo(self.deliveryContainerView!).offset(-10)
            }
            self.paymentLabel?.titleLabel?.text = "支付方式"
            self.paymentLabel?.descriptionLabel?.text = "支付宝"
        }
        
    }
    
    /// 添加剪切板   --  物流
    @objc func deliveryAddPasteboardAction() {
        
        var pasteStr = self.deliveryInfoLabel?.text
        pasteStr = pasteStr?.replacingOccurrences(of: "|", with: "")
        pasteStr = pasteStr?.replacingOccurrences(of: " ", with: "")
        
        let pasteboard = UIPasteboard.general
        pasteboard.string = pasteStr
        
        JDTools.getKeyWindows()?.rootViewController?.view.toast(message: "复制成功")

    }
    
    /// 添加剪切板  -- 海关
    @objc func customsAddPasteboardAction() {
        
        var pasteStr = self.customsInfoLabel?.text
        pasteStr = pasteStr?.replacingOccurrences(of: "|", with: "")
        pasteStr = pasteStr?.replacingOccurrences(of: " ", with: "")
        
        let pasteboard = UIPasteboard.general
        pasteboard.string = pasteStr

        JDTools.getKeyWindows()?.rootViewController?.view.toast(message: "复制成功")
    }
    
    // 支付方式
//    var goodsContainerView: UIView?
//    var storeNameLabel: UILabel?
//    var tagLabel: UILabel?
//    var goodsInfoTableView: UITableView?
    var paymentWayContainerView: UIView?
    var paymentWayTitle: UILabel?
    var paymentWayImageV: UIImageView?
    var paymentWayTableView: UITableView?
    
    func setupPaymentWayView() {
        
        self.paymentWayTitle = UILabel()
        self.contentView.addSubview(self.paymentWayTitle!)
        self.paymentWayTitle?.snp.makeConstraints({ make in
            make.left.equalTo(self.contentView).offset(24)
            make.top.equalTo(self.deliveryContainerView!.snp.bottom).offset(22)
            make.height.equalTo(20)
        })
        self.paymentWayTitle?.labelConfig(textAlignment: .left, font: UIFont.systemFont(ofSize: 14, weight: .semibold), textColor: color("#333333"))
        self.paymentWayTitle?.text = "支付方式"
        
        let inputImgV = UIImageView()
        self.contentView.addSubview(inputImgV)
        inputImgV.snp.makeConstraints { make in
            make.left.equalTo(self.paymentWayTitle!.snp.right).offset(6)
            make.centerY.equalTo(self.paymentWayTitle!)
            make.size.equalTo(CGSizeMake(14, 14))
        }
        inputImgV.image = UIImage(named: "write_image")?.withRenderingMode(.alwaysOriginal)
        
        
        self.paymentWayContainerView = UIView()
        self.contentView.addSubview(self.paymentWayContainerView!)
        
        if self.orderType == .waitingPay || self.orderType == .settlement {
            // 待付款
            self.paymentWayContainerView?.snp.makeConstraints { make in
                make.left.equalTo(self.contentView).offset(12)
                make.right.equalTo(self.contentView).offset(-12)
                make.top.equalTo(self.paymentWayTitle!.snp.bottom).offset(14)
                make.height.equalTo(52*2)
            }
        } else {
            // 其他  不需要显示
            self.paymentWayTitle?.isHidden = true
            inputImgV.isHidden = true
            self.paymentWayContainerView?.snp.makeConstraints { make in
                make.left.equalTo(self.contentView).offset(12)
                make.right.equalTo(self.contentView).offset(-12)
                make.top.equalTo(self.deliveryContainerView!.snp.bottom)
                make.height.equalTo(0)
            }
        }
        self.paymentWayContainerView?.makeCorner(8)
        self.paymentWayContainerView?.backgroundColor = .white
        
        self.paymentWayTableView = UITableView.init(frame: .zero, style: .plain)
        self.paymentWayContainerView?.addSubview(self.paymentWayTableView!)
        self.paymentWayTableView?.snp.makeConstraints({ make in
            make.left.equalTo(self.paymentWayContainerView!)
            make.right.equalTo(self.paymentWayContainerView!)
            make.height.equalTo(52*2)
            make.bottom.equalTo(self.paymentWayContainerView!)
        })
        self.paymentWayTableView?.delegate = self
        self.paymentWayTableView?.dataSource = self
        self.paymentWayTableView?.register(UITableViewCell.self, forCellReuseIdentifier: "paymentCell")
        self.paymentWayTableView?.separatorStyle = .none
        
        self.paymentWayTableView?.reloadData()
    }
    
    var tipsViewTitle: UILabel?
    var hintImgV: UIImageView?
    var tipsContainerView: UIView?
    var tipsLabel: UILabel?
    
    func createTipsView() {
        
        self.tipsViewTitle = UILabel()
        self.contentView.addSubview(self.tipsViewTitle!)
        self.tipsViewTitle?.snp.makeConstraints({ make in
            make.left.equalTo(self.contentView).offset(24)
            make.top.equalTo(self.paymentWayContainerView!.snp.bottom).offset(22)
            make.height.equalTo(22)
        })
        self.tipsViewTitle?.text = "平台提示"
        self.tipsViewTitle?.labelConfig(textAlignment: .left, font: UIFont.systemFont(ofSize: 16, weight: .semibold), textColor: color("#333333"))
        
        self.hintImgV = UIImageView()
        self.contentView.addSubview(self.hintImgV!)
        self.hintImgV?.snp.makeConstraints({ make in
            make.left.equalTo(self.tipsViewTitle!.snp.right).offset(6)
            make.centerY.equalTo(self.tipsViewTitle!)
            make.size.equalTo(CGSize(width: 11, height: 14))
        })
        self.hintImgV?.image = UIImage(named: "hint")?.withRenderingMode(.alwaysOriginal)
        
        self.tipsContainerView = UIView()
        self.contentView.addSubview(self.tipsContainerView!)
        self.tipsContainerView?.snp.makeConstraints({ make in
            make.left.equalTo(self.contentView).offset(12)
            make.right.equalTo(self.contentView).offset(-12)
            make.top.equalTo(self.tipsViewTitle!.snp.bottom).offset(14)
            make.bottom.equalTo(self.contentView).offset(-25)
        })
        self.tipsContainerView?.layer.cornerRadius = 8
        self.tipsContainerView?.backgroundColor = color("#FFFDFA")
        
        self.tipsLabel = UILabel()
        self.tipsContainerView?.addSubview(self.tipsLabel!)
        self.tipsLabel?.snp.makeConstraints({ make in
            make.left.equalTo(self.tipsContainerView!).offset(12)
            make.right.equalTo(self.tipsContainerView!).offset(-12)
            make.top.equalTo(self.tipsContainerView!).offset(12)
            make.bottom.equalTo(self.tipsContainerView!).offset(-12)
        })
        self.tipsLabel?.text = "· 您所购商品是平台依照您的订单申办进口的，所以不能为您提供退货换货响应且可能被拒单，您下单后力争20天内送达；\n· 国内配送费由用户承担，待货品送达后，由用户向承运公司自行支付。\n· 购买跨境商品，平台接单后不接受取消订单或商品退换诉求。"
        
        self.tipsLabel?.labelConfig(textAlignment: .left, font: UIFont.systemFont(ofSize: 14, weight: .regular), textColor: color("#333333"), numberOfLines: 0)
        self.tipsLabel?.addTextLineSpace(spaceHeight: 8)
    }
    
    
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
    func reloadCurrentCell() {
        for subV in self.contentView.subviews {
            subV.removeFromSuperview()
        }
        
        self.goodsCount = self.goodsDetailModel?.goodsList?.count ?? 0
        self.setupUIElements()
        
        self.storeNameLabel?.text = self.shopName
        // 购买人信息
        self.shopperNameLabel?.text = self.goodsDetailModel?.receiverName
        self.shopperTelLabel?.text = String.init(format: "%@ · %@", self.goodsDetailModel?.mobile ?? "", self.goodsDetailModel?.postal ?? "")
        self.shopperAddressLabel?.text = String.init(format: "%@%@%@%@", self.goodsDetailModel?.province ?? "",self.goodsDetailModel?.city ?? "",self.goodsDetailModel?.district ?? "",self.goodsDetailModel?.address ?? "" )
        
        self.deliveryInfoLabel?.text = self.goodsDetailModel?.deliveryNo
        self.orderTimeLabel?.descriptionLabel?.text = self.goodsDetailModel?.orderTime ?? ""
        self.payTimeLabel?.descriptionLabel?.text = self.goodsDetailModel?.payTime ?? ""
        
        self.realNameLabel?.text = self.goodsDetailModel?.buyerName
        self.buyerIdCard?.text = self.goodsDetailModel?.buyerIdCardNumber
        
//        self.goodsDetailModel
        
        
//        self.shopperNameInputView?.text = self.goodsDetailModel?.buyerName
//        self.shopperIDNumberInputView?.text = self.goodsDetailModel?.buyerIdCardNumber
//        
//        self.guanshuiPrice?.descriptionLabel?.text = String.init(format: "￥%.2f", JSON(self.goodsDetailModel?.tariff as Any).doubleValue/1000.0)
//        self.kuajingwuliuPrice?.descriptionLabel?.text = String.init(format: "￥%.2f", JSON(self.goodsDetailModel?.freight as Any).doubleValue/1000.0)
//        
//        self.orderId?.descriptionLabel?.text = self.goodsDetailModel?.orderNo
//        
//        self.shopperNameLabel?.text = self.goodsDetailModel?.buyerName
//        self.shopperIDNumberLabel?.text = self.goodsDetailModel?.buyerIdCardNumber
//        self.shopperMessageInputView?.text = self.goodsDetailModel?.userMessage
//        
//        
//        self.phoneTitleLabel?.text = String.init(format: "客服电话：%@", self.goodsDetailModel?.customerServicePhone ?? "0411-11011011")
//        
//      
//        
//        
//        if self.orderType == .waitingPay {
//            self.orderCreateTime?.descriptionLabel?.text = self.goodsDetailModel?.orderTime
//        }

//        if self.orderType == .alreadyPay || self.orderType == .pickup || self.orderType == .completed || self.orderType == .refusse {
//            self.orderPayTime?.descriptionLabel?.text = self.goodsDetailModel?.payTime
//            self.orderCreateTime?.descriptionLabel?.text = self.goodsDetailModel?.orderTime
//            self.deliveryOrderTime?.descriptionLabel?.text = self.goodsDetailModel?.deliveryTime
//            
//            self.expressId?.text = self.goodsDetailModel?.deliveryNo
//            
//            if self.orderType == .pickup || self.orderType == .completed {
//                self.haiguanID?.descriptionLabel?.text = "海关单号，暂无字段"
//                self.arriveTime?.descriptionLabel?.text = String.init(format: "%@", self.goodsDetailModel?.arrivalTime ?? "--")
//                
//                if self.orderType == .completed {
//                    self.finishTime?.descriptionLabel?.text = self.goodsDetailModel?.finishTime
//                }
//            } else if self.orderType == .refusse {
//                self.haiguanID?.descriptionLabel?.text = "海关单号，暂无字段"
//                self.deliveryOrderTime?.titleLabel?.text = "发货时间"
//                self.deliveryOrderTime?.descriptionLabel?.text = self.goodsDetailModel?.deliveryTime
//            } else if self.orderType == .alreadyPay {
//                self.expressId?.text = ((self.goodsDetailModel?.deliveryNo?.count ?? 0) > 0) ? self.goodsDetailModel?.deliveryNo : "待商家填写运单号"
//                self.expressId?.textColor = color("#8D9198")
//            }
//            
//        }
        
        var goodsTotalPrice: Double = 0.0
        for subModel in self.goodsDetailModel?.goodsList ?? [JDOrderDetailGoodsModel]() {
            goodsTotalPrice = goodsTotalPrice + JSON(subModel.goodsPrice as Any).doubleValue * JSON(subModel.goodsCount as Any).doubleValue
        }
        
        self.goodsTotalPriceView?.descriptionLabel?.text =  String(format: "￥%.2f",  goodsTotalPrice/1000.0)
        self.taxOneView?.descriptionLabel?.text = String(format: "￥%.2f",  JSON(self.goodsDetailModel?.orderAddedTariff as Any).doubleValue/1000.0)
        self.taxTwoView?.descriptionLabel?.text = String(format: "￥%.2f",  JSON(self.goodsDetailModel?.orderConsumptionTariff as Any).doubleValue/1000.0)
        self.sendPriceVIew?.descriptionLabel?.text = String(format: "￥%.2f",  JSON(self.goodsDetailModel?.freight as Any).doubleValue/1000.0)
        self.finalPriceView?.descriptionLabel?.text = String(format: "￥%.2f",  JSON(self.goodsDetailModel?.totalAmount as Any).doubleValue/1000.0)
    }
    
    
    func reloadSettlementCell() {
        for subV in self.contentView.subviews {
            for ssubView in subV.subviews {
                ssubView.snp.removeConstraints()
            }
            subV.snp.removeConstraints()
            
            subV.removeFromSuperview()
        }
        
//        var selectedShopCartModel: JDShopCartModel?
//        var preOrderModel: JDPreOrderModel?
        
        self.goodsCount = self.preOrderModel?.goodsList?.count ?? 0
        self.setupUIElements()
//        {"goodsList":[],"province":"北京市","district":"东城区","totalTariff":0,"totalFreightText":"56.22","totalAmountText":"1691.22","totalAddedTariffText":"135.00","defaultAddressId":57,"totalTariffText":"0.00","shopName":"大连商业投资集团","city":"北京市","postal":"116000","totalAddedTariff":135000,"preOrderId":1098,"preOrderNo":"pre1749369789459","receiverName":"哦哦哦","mobile":"15041702096","totalAmount":1691220,"totalConsumptionTariff":0,"totalConsumptionTariffText":"0.00","customServicePhone":"0411-84664438","address":"啊哈哈哈","totalFreight":56220}
        
        self.storeNameLabel?.text = self.preOrderModel?.shopName
        // 购买人信息
        self.shopperNameLabel?.text = self.preOrderModel?.receiverName
        self.shopperTelLabel?.text = String.init(format: "%@ · %@", self.preOrderModel?.mobile ?? "", self.preOrderModel?.postal ?? "")
        self.shopperAddressLabel?.text = String.init(format: "%@%@%@%@", self.preOrderModel?.province ?? "",self.preOrderModel?.city ?? "",self.preOrderModel?.district ?? "",self.preOrderModel?.address ?? "" )
        
//        params["buyerName"] =  self.currentCell?.buyerInfoModel?.realName
////        "占位购买人姓名"//self.currentCell?.shopperNameInputView?.text
//        params["buyerIdCardNumber"] = self.currentCell?.buyerInfoModel?.idCardNo
        
        self.realNameLabel?.text = self.buyerInfoModel?.realName
        self.buyerIdCard?.text =  self.buyerInfoModel?.idCardNo
     
        
        var goodsTotalPrice: Double = 0.0
        for subModel in self.preOrderModel?.goodsList ?? [JDOrderDetailGoodsModel]() {
            goodsTotalPrice = goodsTotalPrice + JSON(subModel.salePrice as Any).doubleValue * JSON(subModel.goodsCount as Any).doubleValue
        }
        
        self.goodsTotalPriceView?.descriptionLabel?.text = String.init(format: "￥%.2f", goodsTotalPrice/1000.0)
        self.taxOneView?.descriptionLabel?.text = String.init(format: "￥%.2f", JSON(self.preOrderModel?.totalAddedTariff as Any).doubleValue/1000.0)
        self.taxTwoView?.descriptionLabel?.text = String.init(format: "￥%.2f", JSON(self.preOrderModel?.totalConsumptionTariff as Any).doubleValue/1000.0)
        self.sendPriceVIew?.descriptionLabel?.text = String.init(format: "￥%.2f", JSON(self.preOrderModel?.totalFreight as Any).doubleValue/1000.0)
        
        self.finalPriceView?.descriptionLabel?.text = String.init(format: "￥%.2f", JSON(self.preOrderModel?.totalAmount as Any).doubleValue/1000.0)
    }
}

extension JDNewOrderDetailCell: UITableViewDelegate, UITableViewDataSource {
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        if tableView == self.goodsInfoTableView {
            return self.goodsCount
        } else if tableView == self.paymentWayTableView {
            return 2
        }
        return 0
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        if tableView == self.goodsInfoTableView {
            let cell = tableView.dequeueReusableCell(withIdentifier: "goodsCell")
            
            for subV in cell?.contentView.subviews ?? [UIView]() {
                subV.removeFromSuperview()
            }
            
            let goodsInfoView = JDOrderGoodsView()
            cell?.contentView.addSubview(goodsInfoView)
            goodsInfoView.snp.makeConstraints { make in
                make.height.equalTo(104)
                make.top.equalTo(cell!.contentView)
                make.left.equalTo(cell!.contentView)
                make.right.equalTo(cell!.contentView)
            }
            goodsInfoView.bottomLine.isHidden = true
            
    //        goodsSpecificationNameList
            
            let taxOne = UILabel()
            cell?.contentView.addSubview(taxOne)
            taxOne.snp.makeConstraints { make in
                make.top.equalTo(goodsInfoView.snp.bottom).offset(-5)
                make.left.equalTo(goodsInfoView).offset(99)
                make.height.equalTo(17)
            }
            taxOne.labelConfig(textAlignment: .left, font: UIFont.systemFont(ofSize: 12, weight: .regular), textColor: color("#333333"), numberOfLines: 1)
            taxOne.text = "增值税:"
            
            let taxOnePrice = UILabel()
            cell?.contentView.addSubview(taxOnePrice)
            taxOnePrice.snp.makeConstraints { make in
                make.right.equalTo(cell!.contentView).offset(-11)
                make.centerY.equalTo(taxOne)
            }
            taxOnePrice.labelConfig(textAlignment: .right, font: UIFont.systemFont(ofSize: 12, weight: .regular), textColor: color("#333333"), numberOfLines: 1)
            
            
            let taxTwo = UILabel()
            cell?.contentView.addSubview(taxTwo)
            taxTwo.snp.makeConstraints { make in
                make.top.equalTo(taxOne.snp.bottom).offset(5)
                make.height.equalTo(17)
                make.left.equalTo(taxOne)
            }
            taxTwo.labelConfig(textAlignment: .left, font: UIFont.systemFont(ofSize: 12, weight: .regular), textColor: color("#333333"), numberOfLines: 1)
            taxTwo.text = "消费税:"
            
            let taxTwoPrice = UILabel()
            cell?.contentView.addSubview(taxTwoPrice)
            taxTwoPrice.snp.makeConstraints { make in
                make.right.equalTo(cell!.contentView).offset(-11)
                make.centerY.equalTo(taxTwo)
            }
            taxTwoPrice.labelConfig(textAlignment: .right, font: UIFont.systemFont(ofSize: 12, weight: .regular), textColor: color("#333333"), numberOfLines: 1)
            
            if self.orderType == .settlement {
                let goodsModel = self.preOrderModel?.goodsList?[indexPath.row]
                goodsInfoView.goodsName.text = goodsModel?.goodsName
                goodsInfoView.goodsSpec.text = String.init(format: "规格：%@", goodsModel?.specificationName ?? "")
                
                goodsInfoView.goodsNum.text = String.init(format: "数量：%@", goodsModel?.goodsCount ?? 0)
                goodsInfoView.goodsAddress.text = String.init(format: "产地：%@", goodsModel?.origin ?? "")
                
                goodsInfoView.goodsPrice.text =  String.init(format: "￥%.2f", JSON(goodsModel?.salePrice as Any).doubleValue/1000.0 )
                goodsInfoView.goodsPrice.priceString(UIFont.systemFont(ofSize: 12, weight: .regular), UIFont.systemFont(ofSize: 16, weight: .semibold))
                
                if goodsModel?.goodsMainImageUrl?.hasPrefix("http") ?? false  {
                    goodsInfoView.goodsImgV.kf.setImage(with: URL(string: goodsModel?.goodsMainImageUrl ?? ""),placeholder: UIImage(named: "loading_placeholder"))
                } else {
                    goodsInfoView.goodsImgV.downloadImage(goodsModel?.goodsMainImageUrl ?? "")
                }
                
                taxOnePrice.text = String.init(format: "￥%.2f", JSON(goodsModel?.addedTariff as Any).doubleValue/1000.0 )
                
                taxTwoPrice.text =  String.init(format: "￥%.2f", JSON(goodsModel?.consumptionTariff as Any).doubleValue/1000.0 )
            } else {
                let goodsModel = self.goodsDetailModel?.goodsList?[indexPath.row]
                goodsInfoView.goodsName.text = goodsModel?.goodsName
                goodsInfoView.goodsSpec.text = String.init(format: "规格：%@", goodsModel?.specificationName ?? "")
                
                goodsInfoView.goodsNum.text = String.init(format: "数量：%@", goodsModel?.goodsCount ?? 0)
                goodsInfoView.goodsAddress.text = String.init(format: "产地：%@", goodsModel?.origin ?? "")
                
                goodsInfoView.goodsPrice.text = String.init(format: "￥%@", goodsModel?.goodsPriceText ?? "0.00")
                goodsInfoView.goodsPrice.priceString(UIFont.systemFont(ofSize: 12, weight: .regular), UIFont.systemFont(ofSize: 16, weight: .semibold))
                
                if goodsModel?.goodsMainImageUrl?.hasPrefix("http") ?? false  {
                    goodsInfoView.goodsImgV.kf.setImage(with: URL(string: goodsModel?.goodsMainImageUrl ?? ""),placeholder: UIImage(named: "loading_placeholder"))
                } else {
                    goodsInfoView.goodsImgV.downloadImage(goodsModel?.goodsMainImageUrl ?? "")
                }
                
                taxOnePrice.text = String.init(format: "￥%.2f", JSON(goodsModel?.addedTariff as Any).doubleValue/1000.00)//"￥2.00"
                
                taxTwoPrice.text = String.init(format: "￥%.2f", JSON(goodsModel?.consumptionTariff as Any).doubleValue/1000.00)//"￥1.00"
            }
            
            return cell!
        } else {
            let cell = tableView.dequeueReusableCell(withIdentifier: "paymentCell")
            
            cell?.selectionStyle = .none
            for subV in cell?.contentView.subviews ?? [UIView]() {
                subV.removeFromSuperview()
            }
            
            let titleImgV = UIImageView()
            cell?.contentView.addSubview(titleImgV)
            titleImgV.snp.makeConstraints { make in
                make.leading.equalTo(cell!.contentView).offset(12)
                make.centerY.equalTo(cell!.contentView)
                make.size.equalTo(CGSize(width: 22, height: 22))
            }
            
            let paymentWayLabel = UILabel()
            cell?.contentView.addSubview(paymentWayLabel)
            paymentWayLabel.snp.makeConstraints { make in
                make.leading.equalTo(titleImgV.snp.trailing).offset(6)
                make.centerY.equalTo(titleImgV)
            }
            paymentWayLabel.labelConfig(textAlignment: .left, font: UIFont.systemFont(ofSize: 16, weight: .regular), textColor: color("#333333"), numberOfLines: 1)
            if indexPath.row == 0 {
                paymentWayLabel.text = "支付宝"
                titleImgV.image = UIImage(named: "alipay_image")
            } else {
                paymentWayLabel.text = "微信"
                titleImgV.image = UIImage(named: "wechat_image")
            }
            
            let selectedImageV = UIImageView()
            cell?.contentView.addSubview(selectedImageV)
            selectedImageV.snp.makeConstraints { make in
                make.trailing.equalTo(cell!.contentView).offset(-12)
                make.centerY.equalTo(cell!.contentView)
                make.size.equalTo(CGSizeMake(22, 22))
            }
            if self.paymentSelectedIndex == indexPath.row {
                selectedImageV.image = UIImage(named: "circle_selected")
            } else {
                selectedImageV.image = UIImage(named: "circle_unSelected")
            }
            
            return cell!
        }
        
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        if tableView == self.goodsInfoTableView {
            return 148
        } else if tableView == self.paymentWayTableView {
            return 52
        }
        return 0
//        return 104
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        if tableView == self.paymentWayTableView {
            if indexPath.row == self.paymentSelectedIndex {
                self.paymentSelectedIndex = -1
            } else {
                self.paymentSelectedIndex = indexPath.row
            }
            self.paymentWayTableView?.reloadData()
        }
    }
    
}
